package patrol.mobile.com.mobilepatrol.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.utils.Constants;
import patrol.mobile.com.mobilepatrol.utils.SPUtils;


/**
 * Created by shjshi on 2017/8/15.
 */

public class SerEditDialog extends Dialog {
    private EditText et_ser;
    private TextView tv_cancel;
    private TextView tv_sure;
    private SureListener mListener;
    String ser;
    public SerEditDialog(Context context, int themeResId) {
        super(context, themeResId);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_dialog_ser);
        initView();
        initListener();
    }

    private void initListener() {
        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SerEditDialog.this.dismiss();
            }
        });
        tv_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ser = et_ser.getText().toString().trim();
                mListener.onSure(ser);
            }
        });
    }

    public void setmListener(SureListener mListener) {
        this.mListener = mListener;
    }


    public void setEt_ser(String str){
        et_ser.setText(str);
        SPUtils.put(Constants.current_ser,str);
    }
    private void initView() {
        et_ser = ((EditText) findViewById(R.id.et_ser));
        tv_cancel = ((TextView) findViewById(R.id.tv_cancel));
        tv_sure = ((TextView) findViewById(R.id.tv_sure));
        String cur_ser = (String) SPUtils.get(Constants.current_ser,"");
        if (cur_ser!=null&&!cur_ser.equals("")){
            et_ser.setText(cur_ser);
        }
    }
    public interface SureListener{
        void onSure(String ser);
    }
}
